// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.

// ??
import Vue from 'vue';
import ElementUI from 'element-ui';
import * as echarts from 'echarts';

import 'element-ui/lib/theme-chalk/index.css';
import '@/assets/styles/default.scss';

import App from './App';
import store from './store';
import router from './router';
import settings from './settings';
import Video from 'video.js';
import 'video.js/dist/video-js.css';
import hljs from "highlight.js";
import 'highlight.js/styles/atom-one-dark.css';

Vue.prototype.$video = Video

Vue.prototype.settings = settings;
Vue.prototype.$echarts = echarts;

Vue.use(ElementUI);

Vue.directive('highlight',function (el) {
  let blocks = el.querySelectorAll('pre code');
  blocks.forEach((block)=>{
    hljs.highlightBlock(block);
  })
});



// 设置路由跳转的逻辑
router.beforeEach((to, from, next) => {
  if (to.matched.length !== 0) {
    next()
  } else {
    next({ path: '/admin/index' })
  }
});

router.onError((err)=>{
  console.log("router error:",err);
  const pattern = /Loading chunk (\d)+ failed/g;
  const isChunkLoadFailed = err.message.match(pattern);
  const targetPath = router.history.pending.fullPath;
  console.log("target path:",targetPath);
  if (isChunkLoadFailed) {
    window.location.href="/#"+targetPath;
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {App},
  template: '<App/>'
});
